<?php
Util::tsRegisterAssetJs("_formAuditor.js");
/** @var NiniosController $this */
/** @var Ninios $model */
/** @var AweActiveForm $form */
$form = $this->beginWidget('ext.AweCrud.components.AweActiveForm', array(
    'type' => 'horizontal',
    'id' => 'ninios-form',
    'enableAjaxValidation' => false,
    'clientOptions' => array('validateOnSubmit' => true, 'validateOnChange' => false,),
    'enableClientValidation' => true,
        ));
?>

<?php
//segmento codigo para auditoria
if (!$model->isNewRecord) {
    $oldModel = Ninios::model()->findByPk((int)$model->id)->attributes;
    $oldModel['fecha_nacimiento'] = Util::FormatDate($oldModel['fecha_nacimiento'], "Y-m-d");
} else {
    $oldModel = $model->attributes;
}//segmento codigo para auditoria
?>
<script>
    //codigo para auditoria
    var oldModel = <?php echo json_encode($oldModel); ?>;
    var newModel = <?php echo json_encode($model['oldValues']); ?>;
</script>

<div class="row-fluid">
    <div class="span10">
        <?php
        $this->beginWidget('zii.widgets.CPortlet', array(
            'title' => ($model->isNewRecord ? Yii::t('AweCrud.app', 'Registar ') : Yii::t('AweCrud.app', 'Update')) . ' ' . Ninios::label(1),
        ));
        ?>
        <p class="note">
            <?php echo Yii::t('AweCrud.app', 'Fields with') ?>
            <span class="required">*</span>
            <?php echo Yii::t('AweCrud.app', 'are required') ?> 
        </p>
        <div class="row-fluid">
            <div class="span5">
                <?php echo $form->textFieldRow($model, 'cedula', array('maxlength' => 10)) ?>
            </div>
            <div class="span7">
                <?php echo $form->textFieldRow($model, 'nombres', array('maxlength' => 45, 'class' => 'span10')) ?>
            </div>
        </div>
        <div class="row-fluid">
            <div class="span5">
                <?php echo $form->textFieldRow($model, 'apellidos', array('maxlength' => 45)) ?>
            </div>
            <div class="span7">
                <?php echo $form->dropDownListRow($model, 'genero', array('FEMENINO' => 'FEMENINO', 'MASCULINO' => 'MASCULINO',), array('class' => 'span10')) ?>
            </div>
        </div>
        <div class="row-fluid">
            <div class="span5">
                <?php
                if ($model->isNewRecord) {
                    echo $form->datepickerRow($model, 'fecha_nacimiento', array(
                        'readOnly' => 'true',
                        'options' => array(
                            'endDate' => 'now()',
                            'format' => 'yyyy-mm-dd',
                        ),
                        'class' => 'input-large'
                    ));
                } else {
                    if (count($model->datosAntropomorficoses) == 0) {
                        echo $form->datepickerRow($model, 'fecha_nacimiento', array(
                            'readOnly' => 'true',
                            'options' => array(
                                'endDate' => 'now()',
                                'format' => 'yyyy-mm-dd',
                            ),
                            'class' => 'input-large'
                        ));
                    } else {
                        echo $form->textFieldRow($model, 'fecha_nacimiento', array('readOnly' => true));
                    }
                }
                ?>
            </div>
            <div class="span7">
                <?php echo $form->textFieldRow($model, 'representante_cedula', array('maxlength' => 45, 'class' => 'span10')) ?>
            </div>
        </div>
        <div class="row-fluid">
            <div class="span5">
                <?php echo $form->textFieldRow($model, 'representante_nombres', array('maxlength' => 45)) ?>
            </div>
            <div class="span7">
                <?php echo $form->textFieldRow($model, 'representante_apellidos', array('maxlength' => 45, 'class' => 'span10')) ?>
            </div>
        </div>
        <div class="row-fluid">
            <?php echo $form->textFieldRow($model, 'direccion', array('maxlength' => 255, 'class' => 'span11')) ?>
        </div>
        <div class="row-fluid">
            <div class="span5">
                <?php echo $form->textFieldRow($model, 'telefono', array('maxlength' => 45)) ?>
            </div>
            <div class="span7">
                <?php echo $form->textFieldRow($model, 'correo', array('maxlength' => 45, 'class' => 'span10')) ?>
            </div>
        </div>
        <div class="row-fluid">
            <div class="span5">
                <div class="control-group">
                    <?php echo $form->label($model, 'fecha_ingreso', array('class' => 'control-label required')); ?>
                    <div class="controls">
                        <?php
                        $this->widget('bootstrap.widgets.TbDatePicker', array(
                            'model' => $model,
                            'attribute' => 'fecha_ingreso',
                            'options' => array(
                                'format' => 'yyyy-mm-dd',
                            ),
                            'htmlOptions' => array(
                                'disabled' => true,
                                'readonly' => true
                            ),
                        ));
                        ?>
                    </div>
                </div>
            </div>
            <div class="span7">
                <?php
                echo Yii::app()->user->checkAccess("admin") ?
                        $form->dropDownListRow($model, 'institucion_id', array('' => ' -- Seleccione -- ') + CHtml::listData(Institucion::model()->findAll(), 'id', Institucion::representingColumn()), array('class' => 'span10')) :
                        !$model->institucion_id ? $form->dropDownListRow($model, 'institucion_id', array('' => ' -- Seleccione -- ') + CHtml::listData(Institucion::model()->findAll(), 'id', Institucion::representingColumn()), array('class' => 'span10')) :
                                $form->dropDownListRow($model, 'institucion_id', CHtml::listData(Institucion::model()->getInstitucion($model->institucion_id)->findAll(), 'id', Institucion::representingColumn()), array('class' => 'span10'));
                ?>
            </div>
        </div>
        <div class="row-fluid">
            <div class="span5">
                <div class="control-group">
                    <?php echo $form->label($model, 'fecha_salida', array('class' => 'control-label')); ?>
                    <div class="controls">
                        <?php
                        $this->widget('bootstrap.widgets.TbDatePicker', array(
                            'model' => $model,
                            'attribute' => 'fecha_salida',
                            'options' => array(
                                'format' => 'yyyy-mm-dd',
                            ),
                            'htmlOptions' => array(
                                'disabled' => true,
                                'readonly' => true
                            ),
                        ));
                        ?>
                    </div>
                </div>
            </div>
        </div>

        <div id="contenedorAuditoria">
            <div class="row-fluid " id="areaAuditoria" style="visibility: <?php echo ($model->isNewRecord) ? 'hidden' : ''; ?>">
                <div class="span5" id="areaObservacion">
                    <?php echo $form->textFieldRow($model, 'observacion_Auditoria', array('maxlength' => 45, 'id' => "inputObservacion_Auditoria")) ?>
                </div>
                <div class="span5" id="areaArchivo">
                    <?php echo $form->textFieldRow($model, 'archivo_Auditoria', array('maxlength' => 45, 'id' => "inputArchivo_Auditoria")) ?>
                </div>
            </div>
        </div>



        <div class="form-actions">
            <?php
            $this->widget('bootstrap.widgets.TbButton', array(
                'buttonType' => 'submit',
                'type' => 'primary',
                'label' => $model->isNewRecord ? Yii::t('AweCrud.app', 'Create') : Yii::t('AweCrud.app', 'Save'),
            ));
            ?>
            <?php
            $this->widget('bootstrap.widgets.TbButton', array(
                //'buttonType'=>'submit',
                'label' => Yii::t('AweCrud.app', 'Cancel'),
                'htmlOptions' => array('onclick' => 'javascript:history.go(-1)')
            ));
            ?>
        </div>

        <?php $this->endWidget(); ?>
    </div>
    <?php $this->endWidget(); ?>
    <div class="span2">
        <?php
        $this->beginWidget('zii.widgets.CPortlet', array(
            'title' => Yii::t('AweCrud.app', 'Operaciones'),
        ));
        $this->widget('zii.widgets.CMenu', array(
            'items' => $this->menu,
            'htmlOptions' => array('class' => 'operations'),
        ));
        ?>
        <?php $this->endWidget(); ?>
    </div>
</div>
